<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/page/base.jsp"%>
<%@ taglib prefix="d" uri="/doone-comm-ui-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"></base>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title>
<!-- Libraries -->
<link type="text/css" href="<%=path%>/manage/css/layout.css"
	rel="stylesheet" />
<link type="text/css" href="<%=path%>/manage/css/new_style.css"
	rel="stylesheet" />
<link rel="stylesheet" type="text/css"
	href="<%=path%>/manage/css/Tooltip.css" />
<link type="text/css"
	href="<%=path%>/manage/page/user/css/users_style.css" rel="stylesheet" />
<script type="text/javascript"
	src="<%=path%>/manage/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="<%=path%>/manage/js/jquery_form.js"></script>
<script type="text/javascript" src="<%=path%>/manage/js/easyTooltip.js"></script>
<script type="text/javascript"
	src="<%=path%>/manage/js/jquery.wysiwyg.js"></script>
<script type="text/javascript" src="<%=path%>/manage/js/hoverIntent.js"></script>
<script type="text/javascript" src="<%=path%>/manage/js/superfish.js"></script>
<script type="text/javascript" src="<%=path%>/manage/js/custom.js"></script>
<script type="text/javascript"
	src="<%=path%>/manage/js/jquery-ui-1.8.11.custom.min.js"></script>
<script type="text/javascript" src="<%=path%>/manage/js/Tooltip.js"></script>
<script type="text/javascript" src="<%=path%>/manage/js/errorTip.js"></script>
<script type="text/javascript"
	src="<%=path%>/manage/js/jquery.validate.min.js"></script>
<script type="text/javascript"
	src="<%=path%>/manage/js/jquery.validate.methods.min.js"></script>
<script type="text/javascript"
	src="<%=path%>/manage/js/jquery.validate.defaults.js"></script>
<script type="text/javascript">
	function openAddLevel() {
		$("#addConfgiDialog").dialog("open");
	}
	function getUserlevel(levelId){
			$.ajax({
					url : root+	'/clientuser/getUserlevelById.action?levelId='+levelId,
					method : 'post',
					dataType : 'json',
					success : function(data) {
						var userRanks=data.userPointRanks;
						$("#rankName").val(userRanks.rankName);
						$("#minPoints").val(userRanks.minPoints);
						$("#maxPoints").val(userRanks.maxPoints);
						$("#levelId").val(userRanks.id);
						$("#editFlag").val("edit");
						$("#addConfgiDialog").dialog("open");
					},
					error : function(err) {
						if (err.responseText != '')
							alert(err.responseText);
						else
							alert("请求失败！");
					}
				});
	}
	function delField(fieldId){
		if(confirm("确定要删除该条记录")){
			$.ajax({
					url : root+	'/clientuser/deleteUserField.action?fieldId='+fieldId,
					method : 'post',
					dataType : 'json',
					success : function(data) {
					window.location.href=root+"/clientuser/getUserConfigInit.action";
					},
					error : function(err) {
						if (err.responseText != '')
							alert(err.responseText);
						else
							alert("请求失败！");
					}
				});
		}
	}
	
	function chageType(obj){
		var value=$(obj).val();
		 //alert(value);
		if(value=="IMAGERADIO"){
			$("#imageHeaher").show();
			$("#imageValue").show();
		 }else{
		 	$("#imageHeaher").hide();
			$("#imageValue").hide();
		 }
	}
	function addVlaues() {
		var vTb = $("#imageRadio");//得到表格ID=TbData的jquery对象       
		//所有的数据行有一个.CaseRow的Class,得到数据行的大小
		var vNum = $("#imageRadio tr").filter(".CaseRow").size() + 1;//表格有多少个数据行 
		var vTr = $("#imageRadio #trDataRow1"); //得到表格中的第一行数据         
		var vTrClone = vTr.clone(true);//创建第一行的副本对象vTrClone
		vTrClone[0].id = "trDataRow" + vNum;//設置 第一個Id為當前獲取索引；防止重複添加多個ID為trDataRow1的數據行；一次添加一個；
		var vtd=vTrClone.find("td");
		//alert(vtd);
		vtd.find("input").attr("name","fieldImageList["+vNum+"].value");
		vtd.find("input[type='file']").attr("name","fieldImageList["+vNum+"].imageFile");
		vTrClone.appendTo(vTb);//把副本单元格对象添加到表格下方       
	}

	function delVlaues(obj) {
		var vNum = $("#imageRadio tr").filter(".CaseRow").size() + 1;//表格有多少个数据行;
		//alert(1);
		if (vNum <= 2) {
			alert('请至少留一行');
			return;
		}
			//alert(2);
		var vbtnDel = $(obj);//得到点击的按钮对象            
		var vTr = $(obj).parent().parent();//得到父tr对象;  
		//console.log($(obj));
		//alert(vTr.attr("id"));             
		if (vTr.attr("id") == "trDataRow1") {
			alert('第一行不能删除!'); //第一行是克隆的基础，不能删除
			return;
		} else {
			vTr.remove();
		}
	}
	</script>

<script language="javascript" type="text/javascript">
	$(function() {
						$("#addConfgiDialog")
								.dialog(
										{
											autoOpen : false,
											width : 550,
											height : 300,
											modal : true,
											title : '新增字段',
											buttons : {
												"保存" : function() {
												    //gei 图文排序
												   // var fieldTable=$("#imageRadio");
												   // alert(1);
												   $("#addConfig").submit();
												}
											},
											close : function() {
												//清除file输入框里的值
												//$("#addLevelDialog").dialog("close");
											}
										});
										//y验证
										$("#addConfig").validate({
											        rules : {
											            "userConfigDto.fieldName":{
											             required : true
											            },
											            "userConfigDto.reqiured":{
											            required : true
											            },
											            "userConfigDto.fieldType":{
											            required : true
											            }
											        },
											        messages : {
											            "userConfigDto.fieldName":{
											             required : "名称必填"
											            },
											            "userConfigDto.fieldType":{
											             required :"请输入消息标题"
											            },
											            "userConfigDto.reqiured" : {
											             required : "是否必须必填"
											            }
											        }
											    });
					});

</script>
<script type="text/javascript">
 $(function(){
	 var $regAllow=$("input[name='userConfigDto.allowReg']");
	 var $allowType=$("input[name='userConfigDto.allowType']");
	 var $alllowRule=$("input[name='userConfigDto.allowRule']");
	 var $phonwAllowType;
	
	 $.each($allowType,function(){
		 var $this=$(this);
		 if($this.val()=='PHONE'){
			 $phonwAllowType=$this;
		 }
	 });
	 var regAllC=function($this){
		 if($regAllow.filter(":checked").val()==0){
			 $allowType.attr("checked",false);
			 $allowType.attr("disabled",true);
			 $alllowRule.val("");
			 $alllowRule.attr("readonly","readonly");
		 }else{
			 $allowType.attr("checked",true);
			 $allowType.attr("disabled",false);
			 $alllowRule.removeAttr("readonly");
		 }
	 }
	 $regAllow.change(regAllC);
	 var phoneC=function(){
		 if($phonwAllowType.attr("checked")==false){
			 $alllowRule.val("");
			 $alllowRule.attr("readonly","readonly");
		 }else{
			 $alllowRule.removeAttr("readonly");
		 }
	 };
	 $phonwAllowType.click(phoneC);	
	 if($phonwAllowType.attr("checked")==false){
		 $alllowRule.val("");
		 $alllowRule.attr("readonly","readonly");
	 }
	 if($regAllow.filter(":checked").val()==0){
		 $allowType.attr("checked",false);
		 $allowType.attr("disabled",true);
		 $alllowRule.val("");
		 $alllowRule.attr("readonly","readonly");
	 }
	$("input[name='sub']").click(function(){
		var editUrl="${pageContext.request.contextPath}/clientuser/updateUserConfigPre.action"
		var $editForm=$("#configForm");
		$.post(editUrl,$editForm.serialize() ,function(msg){
			alert(msg);
	    });
	});
 })
</script>
</head>
<body>
	<div>
		<p class="sitemap">当前位置：用户信息管理 > 用户配置管理</p>
		<h1>用户配置管理</h1>
		<div>

			<!-- Tabs -->
			<div id="tabs">
				<ul>
					<li><a href="#tabs-1">用户配置</a></li>
				</ul>
				<form method="post" id="configForm">
					<table class="fullwidth" cellpadding="0" cellspacing="0"
						id="enterInfoTab">

						<tr>
							<td>是否允许注册：</td>
							<td><s:radio list="regAllow" key="key" label="value"
									name="userConfigDto.allowReg"></s:radio></td>
						</tr>
						<tr>
							<td>注册可选途径：</td>
							<td><s:checkboxlist list="regType" listKey="key"
									label="value" listValue="value" name="userConfigDto.allowType"></s:checkboxlist>
							</td>
						</tr>
						<tr>
							<td>手机号码规则：</td>
							<td colspan="3"><s:textfield name="userConfigDto.allowRule"
									cssStyle="width:300px" /></td>
							<td><input type="button" name="sub" value="保存修改" /></td>
						</tr>
					</table>
				</form>
				<table>
					<tr>
						<td>注册字段设置：</td>
						<td width="100px">字段名称</td>
						<td width="100px">字段类型</td>
						<td width="100px">对应的值</td>
						<td width="100px">是否必填</td>
						<td>图文</td>
						<td width="80px">操作</td>
						<td><a href="javascript:openAddLevel();" class="btn_addnew"></a>
						</td>
					</tr>
					<s:iterator value="userConfigDto.fieldList" id="filed">
						<tr>
							<td></td>
							<td><s:property value="aliasName" /></td>
							<td><s:property value="typeName" /></td>
							<td><s:property value="#filed.userRegFieldDto.optionValues" />
							</td>
							<td><s:property value="#filed.userRegFieldDto.required" />
							</td>
							<td>
								<table>
									<tr>
										<s:iterator value="#filed.fieldImageList">
											<td><img src="<s:property value="filePath"/>"
												width="50px" height="50px"></td>
										</s:iterator>
									</tr>
								</table>
							</td>
							<td><s:if test="isSysField==false">
									<a href="javascript:;"
										onclick='delField(<s:property value="id"/>)'><img
										src="<%=path%>/manage/images/btn_delete.png"> </a>
								</s:if></td>
						</tr>
					</s:iterator>
				</table>

			</div>
		</div>
	</div>
	<!-- 新增等级dialog -->
	<div id="addConfgiDialog" style="display: none;">
		<form id="addConfig" method="post" enctype="multipart/form-data"
			action="<%=path%>/clientuser/addUserConfig.action">
			<table border="0" cellspacing="1" cellpadding="0">
				<thead>
					<tr>
						<td width="80px"></td>
						<td width="100px"></td>
					</tr>
				</thead>
				<tr>
					<td>字段名称:</td>
					<td><input type="text" name="userConfigDto.fieldName"
						id="fieldName"></td>
				</tr>
				<tr>
					<td>是否必须:</td>
					<td><input type="radio" name="userConfigDto.reqiured"
						value="true"> 是 <input type="radio"
						name="userConfigDto.reqiured" value="false" checked="checked">
						否</td>
				</tr>
				<tr>
					<td>字段类型：</td>
					<td><select name="userConfigDto.fieldType" id="fieldType"
						onchange="chageType(this)">
							<c:forEach var="type" items="${fieldType}">
								<option value="${type.key }">${type.value }</option>
							</c:forEach>
					</select> <input type="hidden" name="userConfigDto.name"
						value="${fieldType['TEXT'] }" /></td>
				</tr>
			</table>
			<!-- 图文处理 -->
			<table id="imageRadio">
				<thead>
					<tr>
						<td width="80px"></td>
						<td width="100px"></td>
						<td width="50px"></td>
					</tr>
				</thead>
				<tr id="trDataRow1" class="CaseRow">
					<td>对应的值：</td>
					<td><input type="text" name="fieldImageList[0].value">
					</td>
					<td id="imageHeaher" style="display: none">图片：</td>
					<td id="imageValue" style="display: none"><input type="file"
						name="fieldImageList[0].imageFile" style="width: 90px"></td>
					<td width="100px"><a href="javascript:addVlaues()"><img
							src="<%=path%>/manage/images/btn_add.jpg"> </a> <a
						href="javascript:;" onclick="delVlaues(this)"><img
							src="<%=path%>/manage/images/btn_delete.png"> </a></td>
				</tr>
			</table>

		</form>
	</div>

</body>
</html>
